<?php
$pagename="Patron Manager";

?>
<?php

if (isset($_GET['status'])) {
echo "Form Processing...<br>Done!";
if ($_GET['status'] == "added") {
echo "<h3><font color='green'>SUCCESS! Write this Down: <b>Barcode: <i>";
echo $_GET["barcode"];
echo "</i> Name (Last, First) <i>";
echo $_GET["lname"];
echo " , ";
echo $_GET['fname'];
echo "</i> Grade: <i>";
echo $_GET['Grade'];
echo "</i> Year: <i>";
echo $_GET['Year'];
echo "</i></font></h3>";
}
if ($_GET['status'] == "notfilled") {
echo "<h3><font color='red'>Please Try Again- ALL FEILDS REQUIRED</font></h3>";
}
}
	
		?>
		
<

<center><h1> <?echo $pagename?> </h1></center><br>
<h3>
Add Patron
<form name="add" method="get" action="patron/patronman_go.php">
First Name: <input type="text" size="40" name="fname"/><br>
Last Name: <input type="text" size="40" name="lname"/><br>
Grade: <select name="grade">
<Option value="0">P</Option>
<Option value="1">K</Option>
<Option value="2">1</Option>
<Option value="3">2</Option>
<Option value="4">3</Option>
<Option value="5">4</Option>
<Option value="6">5</Option>
<Option value="7">5</Option>
<Option value="8">7</Option>
<Option value="9">8</Option>
<Option value="10">9</Option>
<Option value="11">10</Option>
<Option value="12">11</Option>
<Option value="13">12</Option>
</select><br>
Year: <? echo date("Y");?>
<input type="hidden" size="4" value ="<? echo date("Y");?>" name="Year" hidden /><br>
<input type="submit" Value="ADD"/>
</form>
</h3>
<h3>Patron Search</h3>
<form method="get" action="#">
Term: <input type="text" value="<?php if (isset($_GET['term'])) { echo $_GET['term'];} ?>" name="term"/>
For: <select name="where">
<option>Last Name</option>
<option>Code</option>
</select>
<input type="submit" name="submit" />

</form>

<?php
if (isset($_GET['submit'])) {



$term = $_GET['term'];
$where = $_GET['where'];

switch ($where) {
    case "Last Name":
        $where = "lname";
        break;
    case "Code":
         $where = "code";
        break;
   
   }


$sql = mysql_query("select * from patrons where $where like '%$term%'");
$num_rows = mysql_num_rows($sql);
if ($num_rows == 0) {
echo "<font color='red'> <b><i>ERROR:</i> No Person Found Please Try Again</b> </font>";
}
while ($row = mysql_fetch_array($sql)){
	$code = $row['barcode'];
	
	echo '</b><br/> Name: <b>'.$row['fname'].', '.$row['lname'];
	echo '</b><br/> Barcode: <b>'.$row['code'];
    echo '<br/></b>Grade: <b>'.$row['grade'];
	echo '<br/></b> Number Out: <b>'.$row['numout'];
	echo '<br/></b> Total Fines: <b>$'.$row['fines'];
	echo '<br/></b> Total Overdue: <b>'.$row['Overdue'];
	echo "<form action='patroninfo.php' method=get><input type='text' name='code' value='$barcode' disabled><input type='submit' value='view info'>";
	echo '<br><b>----------------------------</b><br><br>';
	}
	}
	?>
	<h3> Preschool is 0 and 12th Grade is 13</h3>
	<h4> To Edit Please Contact The Library Administrator</h4>
<h2>Fines and Blocks MUST be removed by the Library Administrator</h2>